<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var Animal=function(name,age){
            // 私有属性
            var _age=age;
            // 保护属性
            var _color='黑色';
            this.getAge=function(){
                return _age;
            }

            Object.defineProperty(this,'color',{
                set:function(v){
                    _color=v;

                },
                get:function(){
                    return _color;
                }
            });
        }
        
        Animal.prototype.sex=0;
        Animal.prototype.play=function(){
            console.log("哈哈哈哈")
        }

        Animal.num=99;
        Animal.count=function(){
            console.log('种群数量',this.num)
        }

        // 对象
        let xh=new Animal('小黑',2);
        console.log(xh.getAge());
        xh.color='白色'
        console.log(xh.color);
        console.log('性别',xh.sex);
        xh.play();

        console.log('动物类',Animal.num);
        Animal.count();
    </script>
</body>
</html>
